package q891_sumSubseqWidths;

import java.util.Arrays;

public class Solution_2 {
    /*
    子序列宽度之和
     */
    public int sumSubseqWidths(int[] nums) {
        int n = nums.length, mod = (int) (1e9 + 7);
        long ans = 0, pow = 1;
        Arrays.sort(nums);
        for (int i = 0; i < n; i++, pow = (pow * 2) % mod) ans = (ans + pow * (nums[i] - nums[n - i - 1])) % mod;
        return (int) ans;
    }
}
